from helpers.director.shortcut import TablePage,ModelTable,ModelFields,page_dc,director
from .models import ProdModel
from helpers.func.parseExcel import ExcelFields

class ProdModelPage(TablePage):
    def get_label(self):
        return '商品信息'
    def get_template(self, prefer=None):
        return 'jb_admin/table_new.html'
    
    class tableCls(ModelTable):
        model = ProdModel
        exclude =[]
        button_edit = True
        
        
        def dict_head(self, head):
            width  ={
                'no':130,
                'name':140,
                'specification':200,
            }
            head['width'] = width.get(head['name'])
            return head
        
        def get_operations(self):
            ops = super().get_operations()
            ops.append(
                    {'label':'导入EXCEL',
                     'editor':'com-btn',
                      'click_express':ProdModelExcel().get_front_action()
                      }                    
                )
            return ops
         

                
class ProdModelForm(ModelFields):
    class Meta:
        model = ProdModel
        exclude =[]
    
    def get_head_context(self):
        ctx = super().get_head_context()
        ctx.update({
            'width':'650px',
            'height':'300px',
            'title':'创建商品信息'
        })
        return ctx       


class ProdModelExcel(ExcelFields):
    class Meta:
        model = ProdModel
        exclude = []
    
    
director.update({
    'prodmodel':ProdModelPage.tableCls,
    'prodmodel.edit':ProdModelForm,
    'prodmodel.excel':ProdModelExcel
 
})

page_dc.update({
    'prodmodel':ProdModelPage
})